package com.eqs.enterprisequestionnaire.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eqs.enterprisequestionnaire.mapper.OptionMapper;
import com.eqs.enterprisequestionnaire.model.pojo.Option;
import com.eqs.enterprisequestionnaire.model.pojo.Questionnaire;
import com.eqs.enterprisequestionnaire.service.OptionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OptionServiceImpl extends ServiceImpl<OptionMapper, Option> implements OptionService {

    @Resource
    OptionMapper optionMapper;

    public List<Option> selectAll(Option option) {

        Map<String ,Object> params =new HashMap<>();
        params.put("question_id",option.getQuestionId());

        QueryWrapper<Option> queryWrapper= new QueryWrapper<Option>();

        queryWrapper.allEq( params,false);

        return list(queryWrapper);
    }

    /*
    * 获取所以选项ID最大值
    * */
    public Integer selectMaxId(){
        QueryWrapper<Option> queryWrapper= new QueryWrapper<>();
        queryWrapper.select("max(`id`) as id");
        Option option = optionMapper.selectOne(queryWrapper);
        return option != null ? option.getId() : 0;
    }
}
